package com.atguigu.myredis;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;
import redis.clients.jedis.Tuple;

import java.util.Set;

public class RedisUtil {
    public static void main(String[] args) {
        //   Jedis jedis = new Jedis("hdp1", 6379);
        Jedis jedis= RedisUtil.getJedisFromPool();

        jedis.set("k8800","v8800");
        String value = jedis.get("k8800");
        System.out.println(value);
        Set<Tuple> tuples = jedis.zrevrangeWithScores("article:visit",0,9);
        for (Tuple tuple : tuples) {
            System.out.println(tuple);
        }
        jedis.close();

    }

    static JedisPool jedisPool=createPool();

    public static JedisPool createPool(){
        JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
        jedisPoolConfig.setMaxTotal(10);//web应用200-1000  实时计算// 2-16
        jedisPoolConfig.setMaxIdle(5);
        jedisPoolConfig.setMinIdle(5);
        jedisPoolConfig.setBlockWhenExhausted(true);
        jedisPoolConfig.setMaxWaitMillis(5000);
        jedisPoolConfig.setTestOnBorrow(true);


        JedisPool jedisPool = new JedisPool(jedisPoolConfig, "hadoop105", 6379);
        return  jedisPool;

    }

    public static   Jedis  getJedisFromPool(){
        return   jedisPool.getResource();

    }
}
